import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';

export default {
  //获取单据提醒列表
  getNotificationRules(page) {
    return new Promise(function (resolve, reject) {
      httpFetch.get(config.baseUrl + `/api/remind/regulation/list?regulationName=&regulationCode=&page=${page}&size=10`)
        .then(function (res) {
          //添加一个序号
          res.data.map((item,index) => {
            return item._index = index + 1;
          });
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },

  //获取单据提醒列表
  addNotificationRules(params) {
    return new Promise(function (resolve, reject) {
      httpFetch.post(config.baseUrl + '/api/remind/regulation', params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },

  //获取单据提醒列表
  editNotificationRules(params) {
    return new Promise(function (resolve, reject) {
      httpFetch.put(config.baseUrl + '/api/remind/regulation', params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },

  //获取提醒方式值列表
  getNotificationRulesMethods() {
    return new Promise(function (resolve, reject) {
      httpFetch.get(config.baseUrl + '/api/custom/enumerations/template/by/type?type=1014')
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
}
